package com.wb.iec104.utils;

import java.io.FileInputStream;
import java.util.Properties;

/**
 * @author HR
 */
public class PropertiesUtils {
    public static long TIME_END = 0L;
    public static int INIT_THREAD_POOL_SIZE = 10;
    public static int LISTEN_PORT = 60001;

    public static String DETAIL_ID;
    /**
     * 远程心跳IP
     */
    public static String MSTSC_HEART_BEAT_IP;
    /**
     * 远程心跳端口
     */
    public static int MSTSC_HEART_BEAT_PORT;

    public static String TOPIC_NAME;

    public static String STATION_NAME;

    public static String TOPIC_GROUP;


    /**
     * redis address
     */
    public static String REDIS_ADDRESS;

    /**
     * redis port
     */
    public static int REDIS_PORT;


    public static String REDIS_PASSWORD;

    public static long PERIOD;


    static {
        String confPath = System.getProperty("confPath");
        try {

            String[] mess = confPath.split("--");
            // 格式 采集端ip--port--线程池大小--心跳IP--心跳port--topicName--电站名称--gorup
            //e7b9522eaa594b8a91249db8e6ec76c4--null--2407--10--10.120.12.85--10988--T_XNY_GCMY_2407--恭城明阳--T_XNY_GCMY_2407_ANALYSI
            DETAIL_ID = mess[0];
            System.out.println("DETAIL_ID===" + DETAIL_ID);
            try {
                LISTEN_PORT = Integer.parseInt(mess[2]);
                System.out.println(LISTEN_PORT);
            } catch (Exception e) {
                e.printStackTrace();
            }

            try {
                INIT_THREAD_POOL_SIZE = Integer.parseInt(mess[3]);
                System.out.println(INIT_THREAD_POOL_SIZE);
            } catch (Exception e) {
                e.printStackTrace();
            }

            MSTSC_HEART_BEAT_IP = mess[4];
            System.out.println(MSTSC_HEART_BEAT_IP);

            try {
                MSTSC_HEART_BEAT_PORT = Integer.parseInt(mess[5]);
                System.out.println(MSTSC_HEART_BEAT_PORT);
            } catch (Exception e) {
                e.printStackTrace();
            }

            TOPIC_NAME = mess[6];
            System.out.println(TOPIC_NAME);
            STATION_NAME = mess[7];
            System.out.println(STATION_NAME);
            TOPIC_GROUP = mess[8];
            System.out.println(TOPIC_GROUP);

            if (System.getProperty("os.name").toLowerCase().contains("linux")) {
                Properties props = System.getProperties();
                props.load(new FileInputStream("/base/kafka/conf/redis.properties"));
                REDIS_ADDRESS = props.getProperty("redis_ana_address", "127.0.0.1");
                REDIS_PORT = Integer.parseInt(props.getProperty("redis_port", "10547"));
                REDIS_PASSWORD = props.getProperty("redis_password", "Gxfgs2023!");
                PERIOD=Long.parseLong(props.getProperty("period", "5"));
            }

        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

}